package com.ruoyi.resume.controller;

import java.util.HashSet;
import java.util.List;
import java.io.IOException;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.resume.domain.SchoolMajor;
import com.ruoyi.resume.domain.vo.CorporationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.resume.domain.School;
import com.ruoyi.resume.service.ISchoolService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 学校Controller
 * 
 * @author ruoyi
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/school")
public class SchoolController extends BaseController
{
    @Autowired
    private ISchoolService schoolService;

    /**
     * 查询学校列表
     */
    @RequiresPermissions("resume:school:list")
    @GetMapping("/list")
    public TableDataInfo list(School school)
    {
        startPage();
        List<School> list = schoolService.selectSchoolList(school);
        return getDataTable(list);
    }


//    @RequiresPermissions("resume:school:list")
    @PostMapping("/schoolList")
    public Set<CorporationVo> schoolList()
    {

        List<School> list = schoolService.selectSchoolList(new School());
        Set<CorporationVo> corporationVos = new HashSet<CorporationVo>();
        for (School school1 : list) {
            if (school1.getSchoolName()!= null){
            CorporationVo corporationVo = new CorporationVo(school1.getSchoolName());

            corporationVos.add(corporationVo);
            }
        }
        return corporationVos;
    }

    @PostMapping("/schoolMajorList")
    public Set<CorporationVo> schoolMajorList()
    {
        List<SchoolMajor> list = schoolService.selectSchoolMajorList();
        Set<CorporationVo> corporationVos = new HashSet<CorporationVo>();
        for (SchoolMajor schoolMajor : list) {
            if (schoolMajor.getMajor()!= null){
                CorporationVo corporationVo = new CorporationVo(schoolMajor.getMajor());
                corporationVos.add(corporationVo);
            }
        }
        return corporationVos;
    }

    /**
     * 导出学校列表
     */
    @RequiresPermissions("resume:school:export")
    @Log(title = "学校", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, School school)
    {
        List<School> list = schoolService.selectSchoolList(school);
        ExcelUtil<School> util = new ExcelUtil<School>(School.class);
        util.exportExcel(response, list, "学校数据");
    }

    /**
     * 获取学校详细信息
     */
    @RequiresPermissions("resume:school:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(schoolService.selectSchoolById(id));
    }

    /**
     * 新增学校
     */
    @RequiresPermissions("resume:school:add")
    @Log(title = "学校", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody School school)
    {
        return toAjax(schoolService.insertSchool(school));
    }

    /**
     * 修改学校
     */
    @RequiresPermissions("resume:school:edit")
    @Log(title = "学校", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody School school)
    {
        return toAjax(schoolService.updateSchool(school));
    }

    /**
     * 删除学校
     */
    @RequiresPermissions("resume:school:remove")
    @Log(title = "学校", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(schoolService.deleteSchoolByIds(ids));
    }
}
